package logic

import (
	"context"
	"work/model/mysql"

	"work/workrpc/internal/svc"
	"work/workrpc/workrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookAddLogic {
	return &BookAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookAddLogic) BookAdd(in *workrpc.BookAddRequest) (*workrpc.BookAddResponse, error) {
	// todo: add your logic here and delete this line
	book := mysql.Book{
		UserId:  in.UserId,
		StoryId: in.StoryId,
	}
	err := book.BookAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &workrpc.BookAddResponse{
		BookId: int64(book.ID),
	}, nil
}
